package juhe_api

import (
	"encoding/json"
	"errors"
	"io/ioutil"
	"net/http"
)

//聚合
type JuHeReponse struct {
	ErrorCode int    `json:"error_code"` //状态码
	Reason    string `json:"reason"`     //原因
	Result    interface{}
}
type result struct {
	Data []map[string]interface{} `json:"data"` //数据
}

//get请求获取数据
func getApi(url string, resp *JuHeReponse) (err error) {
	r, err := http.Get(url)
	if err != nil {
		return
	}
	defer r.Body.Close()
	data, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return
	}

	err = json.Unmarshal(data, &resp)
	if err != nil {
		return
	}

	if resp.ErrorCode != 0 {
		err = errors.New(resp.Reason)
		return
	}
	return
}
